<?php
/**
 * Creater: 李青林
 * Date Time : 2018/8/15 14:40
 */

namespace App\Http\Controllers;

use App\Http\Models\User;
use Auth;
use DB;
use Illuminate\Http\Request;
use App\Http\Models\CustomerService;
use App\Http\Models\Region;
use Validator;
use Illuminate\Support\Facades\Cache;

class CustomerServiceController extends Controller
{
    public function getCustomerService()
    {
        $typeList = [
            ['type' => 1, 'name' => '运营客服', 'qqList' => []],
            ['type' => 2, 'name' => '商务合作客服', 'qqList' => []],
            ['type' => 3, 'name' => '技术客服', 'qqList' => []],
        ];
        $newTypeList = Cache::remember('CustomerService', 10, function () use ($typeList) {
            $CustomerService = CustomerService::select('id', 'qq', 'type', 'nickName')->orderBy('type', 'asc')->get();
            foreach ($CustomerService as $key => $value) {
                foreach ($typeList as $kk => $vv) {
                    if ($vv['type'] == $value->type) {
                        $typeList[$kk]['qqList'][] = $value;
                    }
                }
            }
            return $typeList;
        });
        return json_encode(['code' => 0, 'msg' => 'ok', 'data' => $newTypeList]);

    }
}